//
//  MQBaseTabBarViewController.m
//  meiquan
//
//  Created by hejingjin on 2017/10/21.
//  Copyright © 2017年 mq. All rights reserved.
//

#import "MQBaseTabBarViewController.h"
#import "HomePageViewController.h"
#import "InfoMationViewController.h"
#import "KaijiangViewController.h"
#import "MineViewController.h"


@interface MQBaseTabBarViewController ()

@end

@implementation MQBaseTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    //1.首页
    [self setupChildVc:[[HomePageViewController alloc] init] title:@"首页" image:@"首页" selectedImage:@"首页-拷贝"];
    
    
    [self setupChildVc:[[KaijiangViewController alloc] init] title:@"开奖" image:@"开奖" selectedImage:@"开奖-拷贝"];
    
    [self setupChildVc:[[InfoMationViewController alloc] init] title:@"资讯" image:@"资讯" selectedImage:@"资讯-拷贝"];
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UINavigationController *minNav = [storyboard instantiateViewControllerWithIdentifier:@"MinNav"];
    [self addChildViewController:minNav];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


+ (void)initialize
{
    
//    DSCQCustomFont *customfont = [DSCQCustomFont shareInstance];
    // 通过appearance统一设置所有UITabBarItem的文字属性
    // 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通过appearance对象来统一设置
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:11]; //未选中字体
    attrs[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"838383"];  //未选中颜色
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];    //选中字体
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"ff8e01"]; //选中颜色
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
      [UITabBar appearance].translucent = NO;
    [[UITabBar appearance] setBarTintColor:[UIColor blackColor]];
  
    
}



 /**
 * 初始化tabbar子控制器
 */

- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置文字和图片
    vc.navigationItem.title = title;
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    
    // 包装一个导航控制器, 添加导航控制器为tabbarcontroller的子控制器
    UINavigationController  *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
    
}

@end
